package com.syq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syq.mapper.DtsAdminMapper;
import com.syq.mapper.DtsBrandMapper;
import com.syq.mapper.DtsCategoryMapper;
import com.syq.pojo.DtsAdmin;
import com.syq.pojo.DtsBrand;
import com.syq.service.DtsBrandService;
import com.syq.util.ResponseUtil;
import com.syq.vo.CatVo;
import com.syq.vo.GoodsAllinone;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: DtsBrandServiceImpl
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/23 15:09
 */

@Service
@Transactional
public class DtsBrandServiceImpl implements DtsBrandService {

    @Autowired
    private DtsBrandMapper brandMapper;

    @Autowired
    private DtsAdminMapper dtsAdminMapper;

    @Autowired
    private DtsCategoryMapper dtsCategoryMapper;

    @Override
    public List<CatVo> findIdAndName() {
        return brandMapper.selectIdAndName();
    }

    @Override
    public Object findAll(Integer page, Integer limit, String sort, String order, String name, Integer id) {
        Map<String,Object> map=new HashMap<>();
        IPage<DtsBrand> dtsBrandIPage = brandMapper.selectPage(new Page<>(page, limit),
                new QueryWrapper<DtsBrand>()
                        .eq("deleted", false)
                        .eq(!StringUtils.isEmpty(name), "name", name)
                        .eq(!StringUtils.isEmpty(id), "id", id)
                        .orderBy(!StringUtils.isEmpty(sort), "Asc".equalsIgnoreCase(order), sort));
        map.put("total",dtsBrandIPage.getTotal());
        map.put("items",dtsBrandIPage.getRecords());
        return ResponseUtil.ok(map);
    }

    @Override
    public Object catAndAdmin() {
        Map<String,Object> map=new HashMap<>();
        List<CatVo> adminList=dtsAdminMapper.selectAll();
        List<CatVo> categoryList = dtsCategoryMapper.selectByPid0();
        map.put("adminList",adminList);
        map.put("categoryList",categoryList);
        return ResponseUtil.ok(map);
    }


}
